/**
 * 1.本代码为云笔记web端开发小组共同拥有。
 * 2.组内成员有 聂道鑫、徐斌强、何瑞、钟倩。
 * 3.联系方式：442342707@qq.com
 */
package com.yunbiji.model;

import java.util.List;

import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Model;
import com.jfinal.plugin.activerecord.Record;

@SuppressWarnings("serial")
/**
 * 笔记本模型类
 * @author 聂道鑫
 *
 */
public class Note_folders extends Model<Note_folders>
{
	public static final Note_folders dao = new Note_folders();

	private String getNoteFoldersSql = "select * from note_folders where tel =? and b_fafolder =?";
	
	private String ifDeleteNoteFoldersSql="select count(*) as counts from note_folders where b_fafolder = ?";
	
	private String getNoteFoldersSqlWhenpId="select * from note_folders where  b_fafolder =? and tel in (?,?)";
	
	
	/**
	 * 获取笔记本
	 * @param tel
	 * @param pIdString
	 * @return
	 */
	public List<Note_folders> getNoteFolders(String tel, String pIdString)
	{
		int pId=Integer.valueOf(pIdString);
		List<Note_folders> list;
		if(pId==1)
		{
			 list= Note_folders.dao.find(getNoteFoldersSqlWhenpId,pId, "roottel",tel);
		}
		else
		{
			 list = Note_folders.dao.find(getNoteFoldersSql, tel,pId);
		}

		return list;
	}
	/**
	 * 删除笔记本
	 * @author niedaoxin
	 * @param idString
	 * @return boolean
	 */
	public boolean deleteNoteFolders(String idString)
	{
		//这里采用的jfinal独有的db+record模式的查询
		int id=Integer.valueOf(idString);
		Record record = Db.findFirst(ifDeleteNoteFoldersSql, id);
		Long counts = record.getNumber("counts").longValue();
		if(counts>0)
		{
			return false;
		}
		else
		{
			Note_folders.dao.deleteById(id);
			return true;
		}
	}
	/**
	 * 返回获取的笔记本名字
	 * @param pId
	 * @return String
	 */
	public String queryStrName(String pId)
	{
		return (Db.queryStr("SELECT b_name From note_folders WHERE id=?",Integer.valueOf(pId)));
	}
	/**
	 * 返回获取的笔记本名字
	 * @param pId
	 * @param tel
	 * @return
	 */
	public String queryStrName(String pId,String tel)
	{
		return (Db.queryStr("SELECT b_name From note_folders WHERE id=? and tel=?",Integer.valueOf(pId),tel));
	}
}
